<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
        "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${packageName}.dao.${classInfo.className}Dao">

    <insert id="insert" useGeneratedKeys="true" keyColumn="id" keyProperty="id"
            parameterType="${packageName}.entity.${classInfo.className}">
        INSERT INTO ${classInfo.tableName}
        (
        <#list classInfo.fieldList as fieldItem >
            ${fieldItem.columnName}<#if fieldItem_has_next>,</#if>
        </#list>
        )
        values (
        <#list classInfo.fieldList as fieldItem >
            ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
        </#list>
        )
    </insert>

    <delete id="delete">
        DELETE FROM ${classInfo.tableName}
        WHERE ${classInfo.primaryKey} = ${r"#{id}"}
    </delete>

    <update id="update" parameterType="${packageName}.entity.${classInfo.className}">
        UPDATE ${classInfo.tableName}
        <set>
            <#list classInfo.fieldList as fieldItem >
                <#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
                    ${r"<if test ='null != "}${fieldItem.fieldName}${r"'>"}${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>${r"</if>"}
                </#if>
            </#list>
        </set>
        WHERE ${classInfo.primaryKey} = ${r"#{"}id${r"}"}
    </update>

    <update id="update2" parameterType="${packageName}.entity.${classInfo.className}">
        UPDATE ${classInfo.tableName}
        <set>
            <#list classInfo.fieldList as fieldItem >
                <#if fieldItem.columnName != "id" && fieldItem.columnName != "AddTime" && fieldItem.columnName != "UpdateTime" >
                    ${fieldItem.columnName} = ${r"#{"}${fieldItem.fieldName}${r"}"}<#if fieldItem_has_next>,</#if>
                </#if>
            </#list>
        </set>
        WHERE ${classInfo.primaryKey} = ${r"#{"}id${r"}"}
    </update>

    <select id="getById" Type="${packageName}.entity.${classInfo.className}">
        SELECT
        *
        FROM ${classInfo.tableName}
        WHERE ${classInfo.primaryKey} = ${r"#{id}"}
    </select>
</mapper>